<template>
	<view>
		<view class="myHavest">
			<view class="egg">
				<view>
					<image src="https://gulimall-void.oss-cn-guangzhou.aliyuncs.com/icon/egg3.png"></image>
					<text>{{userEggCount}}</text>
				</view>
			</view>
			<view class="line"></view>
			<view class="pigeon">
				<view>
					<image src="https://gulimall-void.oss-cn-guangzhou.aliyuncs.com/icon/pigeon.png"></image>
					<text>{{userPigeonCount}}</text>
				</view>
			</view>
		</view>
		<button class="rule" @click="goAdoptionRule">
			认养规则
		</button>
		<view class="listSet">
			<view class="list">
				<view class="title">鸽蛋明细</view>
				<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" v-if="userEggRecord.length==0">
				</u-empty>
				<view class="item" v-for="item in userEggRecord" :key="item.id">
					<view class="left">
						<view class="content">{{item.content}}</view>
						<view class="create_time">{{item.createTime}}</view>
					</view>
					<view class="value">{{item.number > 0 ? '+' : ''}}{{item.number}}</view>
				</view>
			</view>
			<view class="line"></view>
			<view class="list">
				<view class="title">鸽子明细</view>
				<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" v-if="userPigeonRecord.length==0">
				</u-empty>
				<view class="item" v-for="item in userPigeonRecord" :key="item.id">
					<view class="left">
						<view class="content">{{item.content}}</view>
						<view class="create_time">{{item.createTime}}</view>
					</view>
					<view class="value">{{item.number > 0 ? '+' : ''}}{{item.number}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userEggRecord:[],
				userPigeonRecord:[],
				userEggCount:0,
				userPigeonCount:0
			}
		},
		onLoad() {
			this.getUserEggRecord();
			this.getUserPigeonRecord();
		},
		methods: {
			//获取用户鸽蛋记录
			async getUserEggRecord(){
				const res = await this.$myRequest({
					url: 'user/userEggRecord/listByUserId',
					method:'get'
				})
				if(res && res.code === 0){
					this.userEggRecord = res.data;
					this.userEggCount = this.getNumberSum(this.userEggRecord);
				}
			},
			//获取用户鸽子记录
			async getUserPigeonRecord(){
				const res = await this.$myRequest({
					url: 'user/userPigeonRecord/listByUserId',
					method:'get'
				})
				if(res && res.code === 0){
					this.userPigeonRecord = res.data;
					this.userPigeonCount = this.getNumberSum(this.userPigeonRecord);
				}
			},
			getNumberSum(list){
				let sum = 0;
				list.forEach(item=>{
					sum += item.number;
				})
				return sum;
			},
			goAdoptionRule() {
				uni.navigateTo({
					url: '/pages/consultingInformation/consultingInformation'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.myHavest {
		color: white;
		width: 700rpx;
		background-color: #FFB300;
		display: flex;
		margin: 20rpx 25rpx 0 25rpx;
		border-radius: 10px;
		height: 180rpx;
		text-align: center;
		padding-top: 20rpx;

		.egg {
			width: 340rpx;
		}

		.pigeon {
			width: 340rpx;
		}

		image {
			width: 60rpx;
			height: 60rpx;
		}

		text {
			display: block;
		}

		.line {
			height: 200rpx;
			margin-top: -20rpx;
			border-left: 1rpx solid #F8F8F8;
		}
	}


	.rule {
		margin-top: 20rpx;
		border-radius: 30rpx;
		font-size: 30rpx;
		width: 250rpx;
		color: white;
		background-color: #FFB300;
	}

	.listSet {
		display: flex;
		width: 720rpx;
		margin: 25rpx 15rpx 0 15rpx;
	}


	.list {
		min-height: 200rpx;

		.title {
			margin-bottom: 30rpx;
		}

		.item {
			margin-left: 15rpx;
			width: 360rpx;
			padding-bottom: 10rpx;
			margin-bottom: 10rpx;
			display: flex;
			border-bottom: #F8F8F8 solid 0.1rpx;

			.left {
				margin-right: 50rpx;
			}

			.content {
				font-size: 30rpx;
			}

			.create_time {
				color: #808080;
				font-size: 25rpx;
			}
		}
	}
</style>
